﻿using System;
using System.Drawing;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using SenseTimeTracker.Properties;

namespace SenseTimeTracker.Reports
{
	public class MonthlyProjectTotalReportDisplayItem : CommonSenseControls.CommonSenseDisplayPanelItem
	{
		private string frameTotalLabel;
		private string frameRequiredLabel;
		private string frameEstimatedLabel;
		private string frameOvertimeLabel;
		private TimeSpan frameTotal;
		private TimeSpan frameRequired;
		private TimeSpan frameEstimated;
		private TimeSpan frameOvertime;

		public MonthlyProjectTotalReportDisplayItem()
		{
			Height = 100;
			frameTotalLabel = string.Format("{0}:", Resources.ReportTotalLabel);
			frameRequiredLabel = string.Format("{0}:", Resources.ReportRequiredLabel);
			frameEstimatedLabel = string.Format("{0}:", Resources.ReportEstimatedLabel);
			frameOvertimeLabel = string.Format("{0}:", Resources.ReportOvertimeLabel);
		}

		public TimeSpan FrameTotal
		{
			get { return frameTotal; }
			set { frameTotal = value; }
		}

		public TimeSpan FrameRequired
		{
			get { return frameRequired; }
			set { frameRequired = value; }
		}

		public TimeSpan FrameEstimated
		{
			get { return frameEstimated; }
			set { frameEstimated = value; }
		}

		public TimeSpan FrameOvertime
		{
			get { return frameOvertime; }
			set { frameOvertime = value; }
		}

		#region ISenseListItem Members

		public override void OnRender(Graphics g)
		{
			using (Brush blackBrush = new SolidBrush(Color.Black))
			using (Brush redBrush = new SolidBrush(Color.Red))
			using (Font primaryFont = new Font("Helvetica Neue OTS", 9f, FontStyle.Regular))
			{
				SizeF frameTotalSize = g.MeasureString(frameTotalLabel, primaryFont);
				g.DrawString(frameTotalLabel, primaryFont, blackBrush, ClientRectangle.Left + 8, ClientRectangle.Top + ClientRectangle.Height * 1 / 8 - frameTotalSize.Height / 2);
				string stringFrameTotal = frameTotal.TotalHours.ToString("0.00");
				frameTotalSize = g.MeasureString(stringFrameTotal, primaryFont);
				g.DrawString(stringFrameTotal, primaryFont, blackBrush, ClientRectangle.Right - 8 - frameTotalSize.Width, ClientRectangle.Top + ClientRectangle.Height * 1 / 8 - frameTotalSize.Height / 2);

				SizeF frameRequiredSize = g.MeasureString(frameRequiredLabel, primaryFont);
				g.DrawString(frameRequiredLabel, primaryFont, blackBrush, ClientRectangle.Left + 8, ClientRectangle.Top + ClientRectangle.Height * 3 / 8 - frameRequiredSize.Height / 2);
				string stringFrameRequired = frameRequired.TotalHours.ToString("0.00");
				frameRequiredSize = g.MeasureString(stringFrameRequired, primaryFont);
				g.DrawString(stringFrameRequired, primaryFont, blackBrush, ClientRectangle.Right - 8 - frameRequiredSize.Width, ClientRectangle.Top + ClientRectangle.Height * 3 / 8 - frameRequiredSize.Height / 2);

				SizeF frameEstimatedSize = g.MeasureString(frameEstimatedLabel, primaryFont);
				g.DrawString(frameEstimatedLabel, primaryFont, blackBrush, ClientRectangle.Left + 8, ClientRectangle.Top + ClientRectangle.Height * 5 / 8 - frameEstimatedSize.Height / 2);
				string stringFrameEstimated = frameEstimated.TotalHours.ToString("0.00");
				frameEstimatedSize = g.MeasureString(stringFrameEstimated, primaryFont);
				g.DrawString(stringFrameEstimated, primaryFont, blackBrush, ClientRectangle.Right - 8 - frameEstimatedSize.Width, ClientRectangle.Top + ClientRectangle.Height * 5 / 8 - frameEstimatedSize.Height / 2);

				SizeF frameOvertimeSize = g.MeasureString(frameOvertimeLabel, primaryFont);
				g.DrawString(frameOvertimeLabel, primaryFont, blackBrush, ClientRectangle.Left + 8, ClientRectangle.Top + ClientRectangle.Height * 7 / 8 - frameOvertimeSize.Height / 2);
				string stringFrameOvertime = frameOvertime.TotalHours.ToString("0.00");
				frameOvertimeSize = g.MeasureString(stringFrameOvertime, primaryFont);
				g.DrawString(stringFrameOvertime, primaryFont, frameOvertime.TotalHours >= 0 ? blackBrush : redBrush, ClientRectangle.Right - 8 - frameOvertimeSize.Width, ClientRectangle.Top + ClientRectangle.Height * 7 / 8 - frameOvertimeSize.Height / 2);
			}

			base.OnRender(g);
		}
		#endregion
	}
}
